package com.mazaiting.redeye.module.feed

import com.mazaiting.easy.base.bean.Response
import com.mazaiting.easy.base.mvp.IBaseView
import com.mazaiting.easy.utils.rx.RxScheduler
import com.mazaiting.log.L
import com.mazaiting.redeye.api.UserApi
import com.mazaiting.redeye.base.ApplicationComponentImpl
import com.mazaiting.redeye.base.BaseCommonPresenter
import com.mazaiting.redeye.base.CustomConsumer
import com.mazaiting.redeye.base.ICancelPresenter
import com.mazaiting.redeye.bean.FeedBean
import com.mazaiting.redeye.bean.Request
import com.trello.rxlifecycle3.kotlin.bindToLifecycle
import dagger.Component
import io.reactivex.disposables.Disposable
import io.reactivex.functions.Consumer
import javax.inject.Inject

/***
 *
 *
 *                                                    __----~~~~~~~~~~~------___
 *                                   .  .   ~~//====......          __--~ ~~
 *                   -.            \_|//     |||\\  ~~~~~~::::... /~
 *                ___-==_       _-~o~  \/    |||  \\            _/~~-
 *        __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *    _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *  .~       .~       |   \\ -_    /  /-   /   ||      \   /
 * /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 * |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *          '         ~-|      /|    |-~\~~       __--~~
 *                      |-~~-_/ |    |   ~\_   _-~            /\
 *                           /  \     \__   \/~                \__
 *                       _--~ _/ | .-~~____--~-/                  ~~==.
 *                      ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                 -_     ~\      ~~---l__i__i__i--~~_/
 *                                 _-~-__   ~)  \--______________--~~
 *                               //.-~~~-~_--~- |-------~~~~~~~~
 *                                      //.-~~~--\
 *                               神兽保佑
 *                              代码无BUG!
 * @author mazaiting
 * @date 2019-07-08
 * @description 偏好联系人
 */
class WormContract {
    interface View : IBaseView {}
    interface Presenter : ICancelPresenter<View> {
        /**
         * 加载偏好数据
         */
        fun loadFeed()
    }
}

/**
 * 偏好主持人
 */
class WormPresenter
@Inject constructor(
    private val userApi: UserApi
) : BaseCommonPresenter<WormContract.View>(), WormContract.Presenter {
    /**
     * 图虫 Disposable
     */
    private var mFeedDispose: Disposable? = null

    override fun loadFeed() {
        mFeedDispose = userApi.feed(Request(token))
            .compose(RxScheduler.applySchedulers())
            .bindToLifecycle(view.lifecycleProvider)
            .subscribe(object : CustomConsumer<Response<List<FeedBean>>>{
                override fun onSuccess(result: Response<List<FeedBean>>?) {
                    L.d(result?.msg)
                }

            }, Consumer<Throwable> { e ->
                L.d(e.message)
            })
    }

    override fun cancel() {
        mFeedDispose?.dispose()
    }

}

/**
 * 偏好组件
 */
@Component(dependencies = [ApplicationComponentImpl::class])
interface WormComponent {
    /**
     * 注入 Fragment
     */
    fun inject(fragment: WormFragment)
}
